home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Networking / TransferProvider1.0d1 / ProviderFactory.c < prev    next >
Encoding:
Text File  |  1997-09-01  |  2.5 KB  |  88 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        TransferProvider.c
  3.  
  4.     Contains:    Sample that shows how to use OTTransferProviderOwnership.
  5.  
  6.     Written by:    Quinn "The Eskimo!"
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.     You may incorporate this sample code into your applications without
  13.     restriction, though the sample code has been provided "AS IS" and the
  14.     responsibility for its operation is 100% yours.  However, what you are
  15.     not permitted to do is to redistribute the source as "DSC Sample Code"
  16.     after having made changes. If you're going to re-distribute the source,
  17.     we require that you make it clear in the source that the code was
  18.     descended from Apple Sample Code, but that you've made changes.
  19. */
  20.  
  21. ////////////////////////////////////////////////////////////
  22. // Pick up general Open Transport stuff.
  23.  
  24. #include <OpenTransport.h>
  25.  
  26. ////////////////////////////////////////////////////////////
  27. // Pick up OT debugging macros.
  28.  
  29. #include <OTDebug.h>
  30.  
  31. ////////////////////////////////////////////////////////////
  32. // Get our own prototype.
  33.  
  34. #include "ProviderFactory.h"
  35.  
  36. ////////////////////////////////////////////////////////////
  37. // OTDebugStr is not defined in any of the interfaces,
  38. // but it is in the libraries.
  39.  
  40. extern void OTDebugStr(char *str);
  41.  
  42. ////////////////////////////////////////////////////////////
  43.  
  44. static Boolean gOTInited = false;
  45.  
  46. ////////////////////////////////////////////////////////////
  47. // Provider factory routines.
  48.  
  49. extern OSStatus FactoryCreateEndpoint(EndpointRef *ref, OTClient *currentOwner)
  50.     // See comment in interface part.
  51.     // In this example, we arbitrarily create an ADSP endpoint.  This
  52.     // technique works for all types of endpoints.
  53. {
  54.     OSStatus err;
  55.     
  56.     OTAssert("FactoryCreateEndpoint: Parameter error", ref != nil);
  57.     OTAssert("FactoryCreateEndpoint: Parameter error", currentOwner != nil);
  58.     OTAssert("FactoryCreateEndpoint: Called but we weren't successfully inited.", gOTInited);
  59.  
  60.     *currentOwner = OTWhoAmI();
  61.     *ref = OTOpenEndpoint(OTCreateConfiguration("adsp"), 0, nil, &err);
  62.  
  63.     return err;
  64. }
  65.  
  66. ////////////////////////////////////////////////////////////
  67. // Initialisation and termination routines.
  68.  
  69. extern OSStatus InitProviderFactory(void)
  70.     // See comment in interface part.
  71. {
  72.     OSStatus err;
  73.     
  74.     err = InitOpenTransport();
  75.     gOTInited = (err == noErr);
  76.     
  77.     return err;
  78. }
  79.  
  80. extern void CloseProviderFactory(void)
  81.     // See comment in interface part.
  82. {
  83.     OTAssert("CloseProviderFactory: Called but we weren't successfully inited.", gOTInited);
  84.     if (gOTInited) {
  85.         CloseOpenTransport();
  86.     }
  87. }
  88.